package com.demo2do.fms.admin.service.supplier.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.fms.admin.dao.supplier.SupplierProfileDao;
import com.demo2do.fms.admin.service.DataServiceImpl;
import com.demo2do.fms.admin.service.supplier.WareSupplierEmployeeService;
import com.demo2do.fms.entity.supplier.common.Supplier;
import com.demo2do.fms.entity.supplier.ware.WareSiteEmployee;
import com.demo2do.fms.entity.supplier.ware.WareSupplierEmployee;

/**
 * 
 * @author Wy
 *
 */
@Service("wareSupplierEmployeeService")
public class WareSupplierEmployeeServiceImpl extends DataServiceImpl<WareSupplierEmployee> implements  WareSupplierEmployeeService{

    @Dao
    private SupplierProfileDao wareSupplierEmployeeDao;

    /*
     * (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.WareSupplierEmployeeService#listWareSupplierEmployee(java.lang.Long)
     */
    public List<WareSupplierEmployee> listWareSupplierEmployee(Long supplierId) {
        
        return wareSupplierEmployeeDao.listWareSupplierEmployee(supplierId);
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.WareSupplierEmployeeService#create(java.lang.Long, java.util.List)
     */
    public void create(Long supplierId, List<Long> value) {
        
        Supplier supplier = genericDaoSupport.load(Supplier.class, supplierId);
        
        for(int i=0;i<value.size();i++){
            
            WareSupplierEmployee wareSupplierEmployee = new WareSupplierEmployee(supplier,WareSiteEmployee.values()[i].getCode(),WareSiteEmployee.values()[i].getDescription(),value.get(i));
            
            genericDaoSupport.save(wareSupplierEmployee.create());
        }
        
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.fms.admin.service.supplier.WareSupplierEmployeeService#edit(java.util.List, java.util.List)
     */
    public void edit(List<Long> wareSupplierEmployeeIds, List<Long> value) {
        
           for(int i=0;i<wareSupplierEmployeeIds.size();i++){
            
               WareSupplierEmployee wareSupplierEmployee = genericDaoSupport.load(WareSupplierEmployee.class,wareSupplierEmployeeIds.get(i));
                
                genericDaoSupport.update(wareSupplierEmployee.edit( value.get(i)));
            
        }
    }
    
}
